package cn.laixueit.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@Controller
public class LoginController {


    @RequestMapping("/user/login")
    public String login(String name, HttpServletRequest request, HttpServletResponse response) throws IOException {
//        response.sendRedirect();
        if("admin".equals(name)){
            System.out.println("登录成功");
            HttpSession session = request.getSession();
            session.setAttribute("loginStatus",name);
        }
        System.out.println("登录验证方法");
        return "redirect:/main.html";
    }

    @RequestMapping("/logout")
    public String logout(HttpSession session){
        session.removeAttribute("loginStatus");
        return "index";
    }
}
